import json
import numpy as np


class NumpyEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, np.int64):
            return int(obj)
        if isinstance(obj, np.poly1d):
            return obj.coeffs.tolist()
        return super().default(obj)


def read_file(file_path):
    try:
        with open(file_path, 'rb') as file:
            header = file.read(8)
            content = file.read()
        return header, content
    except FileNotFoundError:
        print(f"Error: File {file_path} not found.")
        return None, None
    except Exception as e:
        print(f"Error reading file {file_path}: {e}")
        return None, None


def write_file(file_path, header, content):
    try:
        with open(file_path, 'wb') as file:
            file.write(header)
            file.write(content)
    except Exception as e:
        print(f"Error writing to file {file_path}: {e}")